package likong.bibliothek.pages.status;

import likong.bibliothek.obj.Autor;
import likong.bibliothek.obj.BuchStatus;
import likong.bibliothek.obj.Spender;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.hibernate.Session;


import Persondata.Person;
import Persondata.PersonFormPanel;
import Persondata.PersonWeb;
import db.HibernateHelper;

public class StatusEdit extends StatusAbstract{
	public StatusEdit(final PageParameters params) {
			// Load Person
			
			Session session = HibernateHelper.getSessionFactory().getCurrentSession();
			session.beginTransaction();
			Object ret = session.get(BuchStatus.class, params.getInt("statusID"));
			if (ret == null) {
				// Fehler: Zurück zur Übersicht
				setResponsePage(StatusWeb.class);
				return;
			}
			BuchStatus status = (BuchStatus)ret;
			
//			session.getTransaction()
			
			final CompoundPropertyModel<BuchStatus> model = new CompoundPropertyModel<BuchStatus>(status);
			
			// Panel einfügen
			add(new StatusFormPanel("editStatusFormular", model, "Spender aktualisieren") {
				private static final long serialVersionUID = 1L;

				@Override
				protected void onSubmitModelHandle(IModel<BuchStatus> model) {
					Session session = HibernateHelper.getSessionFactory().getCurrentSession();
					session.beginTransaction();
					session.saveOrUpdate(model.getObject());
					session.getTransaction().commit();
					//session.close();
					this.setResponsePage(StatusWeb.class, params);
				}
			});
			
		}
	}

